package com.leozhang.app;

import java.util.Arrays;
import java.util.List;
import java.util.stream.*;

public class StreamOf {
    public static void main(String[] args) {
        Stream.of("a", "b", "c").forEach(System.out::println);

        Stream.of(new Person("Alice", 25),
                        new Person("Bob", 30),
                        new Person("Charlie", 35))
                .forEach(System.out::println);

        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        System.out.println(list.stream().reduce(0, (a, b) -> a + b));
        System.out.println(list.stream().reduce(0, (a, b) -> a - b)); //?


        List<Integer> ints = Arrays.asList(101, 1002, 93, 64, 35);
        System.out.println("-------------------------");
//        ints.stream().map(i -> i * 2).forEach(System.out::println);
        System.out.println(ints.stream().mapToInt(i -> i * 2).sum());
        System.out.println("-------------------------");
//        ints.stream().forEach(System.out::println);
//        ints.forEach(System.out::println);
//        ints.stream().map(i -> i * 2).forEach(System.out::println);
//        ints.stream().filter(i -> i % 2 == 0).forEach(System.out::println);
//        ints.stream().sorted().forEach(System.out::println);
//        ints.stream().limit(3).forEach(System.out::println);
//        ints.stream().skip(3).forEach(System.out::println);
    }
}
